package com.scfw.start;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * Created by sehuaqi on 2017/7/1.
 */
@RestController
public class HelloController {

    @RequestMapping(value = "/")
    public String index() {
        return "来和 Spring Boot 打个招呼!";
    }

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext context) {

        return args -> {
            System.out.println("我们来看下Spring Boot启动的时候，自动注入了哪些bean:");
            String [] beanNames = context.getBeanDefinitionNames();

            Arrays.sort(beanNames);

            for(String beanName:beanNames){
                System.out.println(beanName);
            }
        };
    }
}
